package com.cloudservice.ccs.controller;

import com.cloudservice.ccs.biz.ICustomerServiceBiz;
import com.cloudservice.ccs.biz.ILoginBiz;
import com.cloudservice.ccs.model.ApiResult;
import com.cloudservice.ccs.entity.CustomerService;
import com.cloudservice.ccs.model.LoginData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
    @Autowired
    private ICustomerServiceBiz customerServiceBiz;

    @Autowired
    private ILoginBiz loginBiz;

    @PostMapping("/login")
    public ApiResult doLogin(@RequestBody LoginData loginData) {
        CustomerService loggedInCustomerService = loginBiz.doLogin(loginData);
        return ApiResult.successWithData(loggedInCustomerService);
    }

    @PostMapping("/logout")
    public ApiResult doLogout() {
        loginBiz.doLogout();
        return ApiResult.success();
    }

    @PostMapping("/register")
    public ApiResult doRegister(@RequestBody CustomerService customerService) {
        customerServiceBiz.save(customerService);
        return ApiResult.success();
    }
}
